package org.thanos.demo.controller;

import lombok.extern.slf4j.Slf4j;
import org.reactivestreams.Publisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@Slf4j
@RestController
public class RSocketClientController {

    @Autowired
    private RSocketRequester rSocketRequester;

    @GetMapping("/publish")
    public Publisher<Void> publish() {
        return rSocketRequester
                .route("publish")
                .data(0x0000)
                .send();
    }

    @GetMapping("/demo")
    public Mono<String> demo() {
        return rSocketRequester
                .route("demo")
                .data(0x0001)
                .retrieveMono(String.class);
    }
}
